package com.example.springbootfoodsafety.dao;

import com.example.springbootfoodsafety.po.Article;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.relational.core.sql.In;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ArtcleDao {
    /***
     * 根据文章id，获取文章类别
     * @param id
     * @return
     */
    @Select("SELECT T.tag_name tag from my_article A LEFT JOIN my_tag T ON A. categorty_id=T.id WHERE A.id=#{id}")
    String getTagName(Integer id);

    /***
     * 修改浏览量功能
     * @param id
     * @return
     */
    @Select("SELECT view_counts count FROM my_article WHERE id=#{id}")
    Integer getView(Integer id);
    @Update("UPDATE my_article SET view_counts=#{count} WHERE id=#{id}")
    boolean modifyView(@Param("id") Integer id,@Param("count") Integer count);

    /***
     * 点赞功能
     * @param id
     * @return
     */
    @Select("SELECT comment_counts FROM my_article WHERE id=#{id}")
    public Integer getZan(Integer id);
    @Update("UPDATE my_article set comment_counts=#{count} WHERE id=#{id}")
    public boolean modifyZan(@Param("id") Integer id,@Param("count") Integer count);

    /**
     * 根据tagId查询该类别下面对应的文章
     * @param id
     */
    @Select("SELECT m.id,m.title,m.summary synopsis,m.create_time dateline,m.body,m.view_counts viewCounts,m.img,u.user_name author,u.avatar authorheaderImg from my_article m LEFT JOIN common_user u on m.author_id=u.id \n" +
            "WHERE m.categorty_id=#{id}")
    public List<Article> getTagForId(Integer id);



}
